home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*__________________________________________________________________________
- |
- | blix.c - the main part of the blix program
- |
- |
- | (c) 1993 Frans van Hoesel, Xtreme graphics software
- | hoesel@chem.rug.nl
- */
-
-
-
- #include <alloca.h>
- #include <math.h>
- #include <gl/gl.h>
- #include <gl/device.h>
- #include <gl/get.h>
- #include <gl/sphere.h>
- #include <gl/image.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
-
- #include "blix.h"
- #include "blixfont.h"
- #include "blixscore.h"
- #include "blixsound.h"
- #include "blixmenu.h"
- #include "blixui.h"
- #include "blixtexture.h"
- #include "bliximage.h"
- #include "blixscore_io.h"
- #include "config.h"
- #include "lod.h"
- #include "maze.h"
- #include "mymath.h"
- #include "players.h"
- #include "transparent.h"
- #include "IvtoGL.h"
-
- int Lod = 2;
- int can_do_textures = 0;
- int notune = 0;
- int noworld = 0;
-
- static float spinrot[4] = {0.0, 0.0, 0.0, 1.0};
- static float rvec[4] ; /* initialized in reset_transforms */
- static float trans[3];
- static int report_nodenum = FALSE;
- static int displmode;
- static int saved_displmode;
- static int zbuf = TRUE;
- static float mouse_clicked[3];
- static float y_pos;
- userinfo_t *inf;
- long zmin, zmax;
-
- extern node_t *the_nodes;
- extern float trackpoint[3];
- extern float trackballsize;
- extern int mouse_dead;
-
- float tb_project_to_sphere(const float r, const float x, const float y);
- int node_closest(float v[3], int nodenum, float mindist);
- int sginap(long);
-
- void remember_view(float *, float *);
- void spin_draw(void);
- void do_menus(void);
- void draw_whatever(void);
- void set_perspective(void);
- void init_windows(void) ;
- void init_menus(void) ;
- void init_path(void) ;
- void build_matrix(void);
- void reset_rot(void);
-
- /* from imagelib: */
- IMAGE *iopen();
- void getrow(IMAGE *, short *, int , int);
- void iclose(IMAGE *);
-
- static float sphere_material[] = {
- DIFFUSE, 0.795918, 0.273554, 0.00686136,
- AMBIENT, 0.0, 0.0, 0.0,
- SPECULAR, 0.48655, 0.319155, 0.444036,
- SHININESS, 86,
- EMISSION, 0.208082, 0.070142, 0.00175932,
- ALPHA, 0.0,
- LMNULL };
- static float sphere_material2[] = {
- DIFFUSE, 0.495918, 0.053554, 0.00286136,
- AMBIENT, 0.0, 0.0, 0.0,
- SPECULAR, 0.48655, 0.319155, 0.444036,
- SHININESS, 86,
- EMISSION, 0.20, 0.030142, 0.00055932,
- ALPHA, 0.0,
- LMNULL };
- static float wall_material[] = {
- DIFFUSE, 0.53, 0.14, 0.0039,
- AMBIENT, 0, 0, 0,
- EMISSION, 0.2, 0.14, 0.0017,
- SPECULAR, 1, 0.991559, 0.963793,
- SHININESS, 66,
- ALPHA, 0.0,
- LMNULL };
- static float darkwall_material[] = {
- DIFFUSE, 0.53, 0.14, 0.0039,
- AMBIENT, 0, 0, 0,
- EMISSION, 0.2, 0.14, 0.0017,
- SPECULAR, 0.1, 0.0991559, 0.0963793,
- SHININESS, 66,
- ALPHA, 0.0,
- LMNULL };
- static float topwall_material[] = {
- DIFFUSE, 0.14, 0.06, 0.31,
- AMBIENT, 0, 0, 0,
- EMISSION, 0.2, 0.14, 0.0017,
- SPECULAR, 0.1, 0.0991559, 0.0963793,
- SHININESS, 66,
- ALPHA, 0.0,
- LMNULL };
-
- static float light1[] = {
- POSITION, -1.0, 2.0, 1.0, 0.0,
- LMNULL } ;
- static float light2[] = {
- POSITION, 1.0, 2.0, -1.0, 0.0,
- LCOLOR, 0.7, 1.0, 1.0,
- AMBIENT, -0.2, -0.2, -0.2,
- LMNULL } ;
- static float light3[] = {
- POSITION, 0, 0.75, 0.0,
- LMNULL };
-
- static float light4[] = {
- POSITION, 1.0, -2.0, 1.0, 0.0,
- LMNULL } ;
- static float light0[] = {
- LMNULL } ;
- static float lmodel[] = {
- AMBIENT, 0.1, 0.1, 0.1,
- LMNULL } ;
- static float lmodel0[] = {
- LMNULL } ;
- static float material0[] = {
- LMNULL } ;
- static float sphere[4] = { 0,0,0, 0.999};
-
- Matrix rotmat;
- Matrix invrotmat;
- char *basename;
- char *datadir;
- int no_sfx = 1;
- int playing_tune = 0;
- int current_tune = 0;
- int display_scene = 1;
-
-
- /*__________________________________________________________________
- |
- | main
- */
-
- int main(int argc, char *argv[]) {
-
- char *m;
- /* keep basename, for error messages */
- basename = strdup( argv[0]);
- if (strrchr(basename,'/') != NULL) {
- basename = strrchr(basename,'/')+1;
- }
- if (argc >= 2) {
- if (strcmp (argv[1],"-s") == NULL ||
- strcmp(argv[argc-1], "-s") == NULL) {
- notune = 1;
- }
- if (strcmp(argv[1], "-w") == NULL ||
- strcmp(argv[argc-1], "-w") == NULL) {
- noworld = 1;
- }
- }
- init_path();
- display_scene = INTRO;
- init_tmpdir();
- init_windows();
- init_ui();
- init_fonts();
- draw_whatever2d();
- no_sfx = init_sound();
- current_tune = SFX_TUNE_A;
- if (notune) {
- toggle_tune();
- toggle_tune();
- } else {
- /* the sleep makes things work as they should,
- */
- sleep(1);
- sfx(SFX_WELCOME);
- sleep(2);
- toggle_tune();
- playing_tune = 1;
- sfx(current_tune);
- }
- init_server();
- init_alpha();
- init_maze();
- init_menus();
- init_players();
- init_textures();
- /* final brutal check for memory if this fails, then probably one of
- * the unchecked mallocs failed too
- */
- m = (char *) malloc(200000);
- if (m == NULL) {
- fprintf(stderr, "%s: Not Enough Memory\n", basename);
- exit_program();
- }
- free(m);
- doscore(0);
- gflush();
- reset_transforms();
- backface(TRUE);
- lmdef(DEFMATERIAL, 1, sizeof(sphere_material), sphere_material);
- lmdef(DEFMATERIAL, 2, sizeof(wall_material), wall_material);
- lmdef(DEFMATERIAL, 3, sizeof(darkwall_material), darkwall_material);
- lmdef(DEFMATERIAL, 4, sizeof(topwall_material), topwall_material);
- lmdef(DEFMATERIAL, 5, sizeof(sphere_material2), sphere_material2);
- lmdef(DEFMATERIAL, 10, sizeof(material0), material0);
- lmdef(DEFLMODEL, 1, sizeof(lmodel), lmodel);
- lmdef(DEFLMODEL, 10, sizeof(lmodel0), lmodel0);
- lmdef(DEFLIGHT, 1, sizeof(light1), light1);
- lmdef(DEFLIGHT, 2, sizeof(light2), light2);
- lmdef(DEFLIGHT, 3, sizeof(light3), light3);
- lmdef(DEFLIGHT, 4, sizeof(light4), light4);
- lmdef(DEFLIGHT, 10, sizeof(light0), light0);
- lmbind(LMODEL, 1);
- lmbind(LIGHT0, 1);
- if (Lod >= EXTRA_LIGHT )
- lmbind(LIGHT1,2);
- sphmode(SPH_TESS, SPH_OCT);
- sphmode(SPH_HEMI, TRUE);
- /* the next line may seem strange for speedy spheres
- * but it saves a few micro seconds, because the matrix
- * at the time of calling sphdraw, is always oriented
- */
- sphmode(SPH_ORIENT, FALSE);
- sphmode(SPH_PRIM, SPH_MESH);
- if (Lod >= EXTRA_FINE)
- sphmode(SPH_DEPTH, 12);
- else
- sphmode(SPH_DEPTH, 11);
- shademodel(GOURAUD);
- build_maze(0, Lod);
- reshapeviewport();
- zbuffer(zbuf);
- display_scene = GAME;
- draw_whatever();
- uimode = MODE3D;
- start_full_menu();
- ui();
- exit_program();
- return 0;
- }
-
- void exit_program(void) {
- tune_off();
- sleep(1);
- end_sound();
- sginap(CLK_TCK/4);
- gexit();
- exit (0);
- }
-
- /*___________________________________________________________________
- |
- | init_path - find the path leading to the directory with blix data.
- |
- | the path to all the data files for blix is determined only once,
- | by searching for the file blix.dat. (this file is used for nothing
- | else; forget about its cryptic contents it's just a joke)
- | specific testing is done for Indyzone path, and relative path
- | on the developers CD, also DATADIR (defined at compile time),
- | the current directory and the environment variable BLIXDIR are
- | checked.
- |
- */
-
- void init_path(void) {
- int f;
- char fullpath[512];
-
- f = -1;
- datadir = getenv("BLIXDIR");
- if (datadir != NULL) {
- strcpy(fullpath, datadir);
- strcat(fullpath, "/blix.dat");
- f = open(fullpath, O_RDONLY);
- }
- #ifdef DATADIR
- if (f == -1) {
- strcpy(fullpath, DATADIR);
- strcat(fullpath, "/blix.dat");
- f = open(fullpath, O_RDONLY);
- }
- #endif
- if (f == -1) {
- strcpy(fullpath, "/usr/demos/IndiZone/.data/blix/blix.dat");
- f = open(fullpath, O_RDONLY);
- }
- if (f == -1) {
- strcpy(fullpath, "../data/blix/blix.dat");
- f = open(fullpath, O_RDONLY);
- }
- if (f == -1) {
- strcpy(fullpath, "./blix.dat");
- f = open(fullpath, O_RDONLY);
- }
- if (f == -1) {
- fprintf(stderr,"%s: unable to find blix.dat needed for running"
- " blix.\n", basename);
- exit(1);
- }
- close(f);
- datadir = strdup(fullpath);
- /* strip off the blix.dat part */
- *(strrchr(datadir, '/')+1) = '\0';
- }
-
- /*_________________________________________________________________
- |
- | remember_view - is called from the ui routine.
- |
- | in t[0] I encode the operation to be done (pan/zoom); the
- | parameters of the operation are in t[1] and t[2].
- |
- */
-
- void remember_view(float *r, float *t) {
-
- int nodenum;
-
- /* first time, switch to double buffered mode */
- if (displmode == DMRGB) {
- sfx(SFX_BEEP);
- cpack(0x00000000);
- clear();
- gflush();
- displmode = DMRGBDOUBLE;
- doublebuffer();
- gconfig();
- gflush();
- cpack(0x0000000);
- if (zbuf) {
- czclear(0x00000000, zmax);
- swapbuffers();
- czclear(0x00000000, zmax);
-
- } else {
- clear();
- swapbuffers();
- clear();
- }
- }
- /* t is an array of three floats, the first holds the 'command'
- * the other two, the parameters; silly, but compatible.
- */
- if (t[0] == 0) {
- /* 'pan' */
- /* not really panning, just record the mouse position, and use
- * that to guide blix around the maze.
- */
- mouse_clicked[0] = t[1];
- mouse_clicked[1] = t[2];
- trackpoint[0] = t[1];
- trackpoint[1] = t[2] - y_pos;
- trackpoint[2] = tb_project_to_sphere(trackballsize*1.005,
- trackpoint[0], trackpoint[1]);
- vtransform(trackpoint, invrotmat, trackpoint);
- vnormal(trackpoint);
- if (report_nodenum) {
- nodenum = node_closest(trackpoint, -1, 0.0001);
- if (nodenum >= 0) {
- fprintf(stderr,"node %d: %f %f %f distance %f\n", nodenum,
- the_nodes[nodenum].pos[0],
- the_nodes[nodenum].pos[1],
- the_nodes[nodenum].pos[2],
- vdistance(the_nodes[nodenum].pos, trackpoint));
- }
- }
- add_quats(spinrot, rvec, rvec);
- build_matrix();
- } else if (t[0] == 1) {
- /* zoom */
- trans[2] += t[2]*6;
- if (trans[2] > -1.1* SCALE)
- trans[2] = -1.1 * SCALE;
- trans[0] = 0;
- /* zoom not only zooms in, but also translates a bit, so you
- * don't zoom in via a straight line to the center, but via
- * an exponential line towards a point above the pole
- */
- trans[1] = -1.8*exp(trans[2]/14)+0.662;
- if (trans[1] > 0) trans[1] = 0;
- set_perspective();
- spinrot[0] = 0;
- spinrot[1] = 0;
- spinrot[2] = 0;
- spinrot[3] = 1;
- } else if (t[0] == 2) {
- /* Remember the rotation so we can spin... */
- spinrot[0] = r[0];
- spinrot[1] = r[1];
- spinrot[2] = r[2];
- spinrot[3] = r[3];
- add_quats(r, rvec, rvec); /* And add on more rotation */
- build_matrix();
- }
- draw_whatever(); /* And draw the scene */
- }
-
-
- /*__________________________________________________________________
- |
- | switch_single - switch to single buffer RGB mode
- |
- | set the color to some color that looks appr. the same in both buffer
- | modes, like cpack(0x00332244), or simply black or white.
- | But set that color before you call this routine.
- |
- */
-
- void switch_single(void) {
-
- if (displmode == DMRGBDOUBLE ) {
- displmode = DMRGB;
- frontbuffer(TRUE);
- clear();
- frontbuffer(FALSE);
- gflush();
- singlebuffer();
- gconfig();
- }
-
- }
-
- /*___________________________________________________________________
- |
- | switch_double - switch to double buffer RGB mode
- |
- */
-
- void switch_double(void) {
-
- cpack(0x0000000);
- if (displmode == DMRGB) {
- clear();
- gflush();
- displmode = DMRGBDOUBLE;
- doublebuffer();
- gconfig();
- gflush();
- }
- clear();
- }
-
- /*__________________________________________________________________
- |
- | save_displaymode - save current display mode
- |
- */
-
- void save_displaymode(void) {
- saved_displmode = displmode;
- }
-
- /*__________________________________________________________________
- |
- | restore_displaymode - restore mode from saved state
- |
- */
-
- void restore_displaymode(void) {
- if (displmode != saved_displmode) {
- switch (saved_displmode) {
- case DMRGBDOUBLE:
- switch_double();
- break;
- case DMRGB:
- switch_single();
- break;
- }
- }
- }
-
-
- /*__________________________________________________________________
- |
- | spin_draw - draw spinning world
- |
- */
-
- void spin_draw(void) {
- /*
- * The ui_quiet flag is defined in "ui.h", and is
- * kept up-to-date by the ui() routines. When
- * ui_quiet is FALSE, leave the object alone to let the
- * user interact with it.
- */
- if (ui_quiet) {
- if (displmode == DMRGB) {
- sfx(SFX_BEEP);
- cpack(0x00000000);
- clear();
- gflush();
- displmode = DMRGBDOUBLE;
- doublebuffer();
- gconfig();
- gflush();
- cpack(0x0000000);
- if (zbuf) {
- czclear(0x00000000, zmax);
- swapbuffers();
- czclear(0x00000000, zmax);
-
- } else {
- clear();
- swapbuffers();
- clear();
- }
- }
- if (spinrot[0] != 0 || spinrot[1] != 0 || spinrot[2] != 0
- || spinrot[3] != 1) {
- add_quats(spinrot, rvec, rvec); /* rotate again */
- build_matrix();
- }
- draw_whatever(); /* And draw the scene */
- }
- }
-
-
- extern int score;
- extern int highscore;
-
- /* ARGSUSED */
- void draw_whatever(void) {
- float val;
- char *c;
- char st[20];
- float x, alph;
-
- zbuffer(zbuf);
- switch (display_scene) {
- case GAME:
- pushmatrix();
- if (mouse_dead) {
- sphere[3]+=0.008;
- mouse_dead++;
- if (sphere[3] > 1.2 && mouse_dead>60) {
- sphere[3] = 0.999;
- sleep(1);
- mouse_dead = 0;
- doscore(score);
- score = 0;
- switch_double();
- zbuffer(zbuf);
- reset_rot();
- }
- }
- val = trans[2]*SCALE*TANFOVY;
- ortho(val, -val, val, -val, NEAR, -trans[2] + EXTRA);
- y_pos = trans[1]/(-val);
- cpack(0x00000000);
- if (zbuf) {
- czclear(0x00000000, zmax);
- } else {
- clear();
- }
- translate(trans[0], trans[1], trans[2]);
- players_action();
-
- if (Lod >= TEXTURE_MAPS && can_do_textures) {
- lmbind(MATERIAL, 5);
- } else {
- lmbind(MATERIAL,1);
- }
- lmbind(LIGHT0,1);
- sphdraw(sphere);
- draw_maze(rotmat, zbuf);
- draw_players(rotmat, invrotmat);
-
- popmatrix();
- pushmatrix();
- zbuffer(FALSE);
- ortho2(-1,1, -1, 1);
- if (mouse_dead > 5) {
- /* draw a black square, but with appropiate alpha, so
- * it the scene slowly fades away
- */
- alph = 1.0-(mouse_dead-5)/24.0;
- if (alph < 0 ) {
- alph = 0;
- } else if (alph > 1.0) {
- alph = 1.0;
- }
- set_alpha(alph);
- cpack(0x00000000);
- rectfi(-1, -1, 1, 1);
- set_alpha(0);
- }
- sprintf(st, "%d",score);
- c = st;
- x = -0.8;
- while (*c) {
- pushmatrix();
- translate(x, -0.9, 0);
- callobj(8000 + *c - '0');
- popmatrix();
- x+= 0.05;
- c++;
- }
- if (highscore != 0) {
- sprintf(st, "%d", highscore);
- c = st;
- x = 0.70;
- while (*c) {
- pushmatrix();
- translate(x, -0.9, 0);
- callobj(8000 + *c - '0');
- popmatrix();
- x+= 0.05;
- c++;
- }
-
- }
- if (mouse_dead) {
- /* draw the word 'dead' (obj 7000), scale it so it grows
- * and in the end make it fade away, by increasing alpha
- */
- x = mouse_dead/20.0+0.2;
- if (x > 1.7) {
- x = 1.7;
- }
- if (mouse_dead > 40 ) {
- alph = (mouse_dead-40)/20.0;
- set_alpha(alph);
- }
- translate(0,0.4,0);
- /*rotate((x-0.2)/1.5 * 3600, 'z');*/
- scale(x,x,x);
- callobj(7000);
- set_alpha(0);
- }
- popmatrix();
- if (displmode == DMRGBDOUBLE )
- swapbuffers(); /* Show what we just drew */
- break;
- default:
- /* something is wrong, but call draw_whatever2d to handle it */
- printf("WRONG\n");
- draw_whatever2d();
-
- }
- }
-
- void draw_whatever2d(void) {
- IMAGE *image;
- char tmpstr[256];
- int i;
- float v1[3];
-
- zbuffer(FALSE);
- subpixel(TRUE);
- if (displmode == DMRGBDOUBLE ) {
- switch_single();
- clear();
- gflush();
- }
- pushmatrix();
- ortho2(0,1,0,1);
- bgnpolygon();
- v1[0] = 0; v1[1] = 1; cpack(0x000022bb);
- v2f(v1);
- v1[1] = 0; cpack(0x000061ff);
- v2f(v1);
- v1[0] = 1; cpack(0x000052ff);
- v2f(v1);
- v1[1] = 1; cpack(0x000038ff);
- v2f(v1);
- endpolygon();
- switch (display_scene) {
- case SORRY:
- getsize(&sizey, &sizey);
- ortho2(0, sizex, 0, sizey);
- set_fontcolor(0x0000A0A0, 0x00E0E0);
- set_fontsize(0.075);
- draw_stringXY(0.10, 0.9, "S O R R Y");
- set_fontsize(0.060);
- set_fontcolor(0x00b0b0, 0x00c0c0);
- draw_stringXY(0.20, 0.72,
- "For some reason Blix is\n"
- "not able to connect to \n"
- "the server that keeps\n"
- "track of the highscores.\n\n\n"
- "See the man page for\n"
- "more details.");
- gflush();
- break;
- case PAUSED:
- strcpy(tmpstr, datadir);
- strcat(tmpstr, "blixphoto.rgb");
- image = iopen(tmpstr, "r");
- if (image == NULL) {
- fprintf(stderr,"%s: cannot locate photo image\n", basename);
- exit_program();
- }
- draw_image(image, 0.05, 0.25, 0.70, 0.90);
- getsize(&sizey, &sizey);
- ortho2(0, sizex, 0, sizey);
- set_fontcolor(0x0000A0A0, 0x00E0E0);
- set_fontsize(0.20);
- draw_stringXY(0.21, 0.63, " Game\nPaused");
- set_fontsize(0.05);
- draw_stringXY(0.37, 0.05, "Click mouse to continue...");
- gflush();
- break;
- case INTRO:
- strcpy(tmpstr, datadir);
- strcat(tmpstr, "blixrt.rgb");
- image = iopen(tmpstr, "r");
- if (image == NULL) {
- fprintf(stderr,"%s: cannot locate intro image\n", basename);
- if (no_sfx == 0 )
- end_sound();
- gexit();
- exit(1);
- }
- ortho2(0, 1, 0, 1);
- draw_image(image, 0.05, 0.50, 0.05, 0.85);
- iclose(image);
- getsize(&sizey, &sizey);
- ortho2(0, sizex, 0, sizey);
- set_fontcolor(0x0000A0A0, 0x00E0E0);
- set_fontsize(0.070);
- draw_stringXY(0.60, 0.9, "WELCOME");
- set_fontsize(0.050);
- draw_stringXY(0.59, 0.82,
- "My name is Blix.\n"
- "I am the not too\n"
- "undestructable\n"
- "hero of this game.\n\n"
- "Use the right\n"
- "mousebutton to\n"
- "popup the menu");
- draw_stringXY(0.59, 0.26,
- "Loading data...\n"
- "Please wait.");
- draw_stringXY(0.59, 0.13,
- "Blix is written by\n"
- "Frans van Hoesel\n");
- zbuffer(zbuf);
- gflush();
- break;
-
- case PRIVATHIGH:
- getsize(&sizex, &sizey);
- inf = getinf();
- ortho2(0, sizex, 0, sizey);
- set_fontcolor(0x0000A0A0, 0x00E0E0);
- set_fontsize(0.078);
- draw_stringXY(0.05, 0.92, "Y");
- draw_stringXY(0.076, 0.92, "our personal highscores:");
- sprintf(tmpstr,"after %d runs", (int)privatlist.game);
- set_fontsize(0.043);
- draw_stringXY(0.35, 0.85, tmpstr);
- for (i=0; i< 7; i++) {
- set_fontcolor((7.0-i)*0x202203, (7-i)*0x242400);
- draw_stringXY(0.65, 0.77 - i * 0.1, privatlist.names[i]);
- set_fontcolor((11.0-i)*0x111213, (11-i)*0x131313);
- draw_stringXY(0.56, 0.77 - i * 0.1, "pts");
- }
- set_fontsize(0.053);
- for (i=0; i<7; i++) {
- set_fontcolor((7-i)*0x202000, (7-i)*0x242400);
- sprintf(tmpstr, "%d", (int)privatlist.scores[i]);
- draw_stringXY(0.55 - (strlen(tmpstr)* 0.032), 0.77 - i * 0.1, tmpstr);
- }
- set_fontcolor(0x05122d, 0x08102D);
- draw_stringXY(0.05, 0.105, inf->name);
- draw_stringXY(0.05, 0.04, inf->host);
- image = NULL;
- if (inf->image != NULL && *(inf->image) != '\0')
- image = iopen(inf->image, "r");
- if (image == NULL) {
- strcpy(tmpstr, datadir);
- strcat(tmpstr, "noimage.rgb");
- image = iopen(tmpstr, "r");
- }
- if (image != NULL) {
- draw_image(image, 0.05, 0.35, 0.50, 0.80);
- iclose(image);
- }
- gflush();
- break;
- case SYSTEMHIGH:
- getsize(&sizex, &sizey);
- ortho2(0, sizex, 0, sizey);
- set_fontcolor(0x0000A0A0, 0x00E0E0);
- set_fontsize(0.060);
- draw_stringXY(0.04, 0.94, "The Best Players on your System:");
- sprintf(tmpstr,"after %d runs", (int)systemlist.game);
- set_fontsize(0.043);
- draw_stringXY(0.35, 0.87, tmpstr);
- for (i=0; i< 7; i++) {
- set_fontcolor((7.0-i)*0x202203, (7-i)*0x242400);
- if (systemlist.names[i] != NULL &&
- *(systemlist.names[i]) != '\0') {
- draw_stringXY(0.57, 0.74 - i * 0.1, systemlist.names[i]);
- }
- set_fontcolor(0x05122d, 0x08102D);
- if (systemlist.hosts[i] != NULL &&
- *(systemlist.hosts[i]) != '\0') {
- strcpy(tmpstr,"(");
- strcat(tmpstr, systemlist.hosts[i]);
- strcat(tmpstr,")");
- draw_stringXY(0.57, 0.69 - i * 0.1, tmpstr);
- }
- set_fontcolor((11.0-i)*0x111213, (11-i)*0x131313);
- draw_stringXY(0.50, 0.74 - i * 0.1, "pts");
- }
- set_fontsize(0.053);
- for (i=0; i<7; i++) {
- set_fontcolor((7-i)*0x202000, (7-i)*0x242400);
- sprintf(tmpstr, "%d", (int) systemlist.scores[i]);
- draw_stringXY(0.49 - (strlen(tmpstr)* 0.032), 0.74 - i * 0.1, tmpstr);
- }
- for (i=0; i<7; i++) {
- image = NULL;
- if (systemlist.images[i] != NULL && *(systemlist.images[i]) != '\0')
- image = iopen(systemlist.images[i], "r");
- if (image == NULL) {
- strcpy(tmpstr, datadir);
- if (strncmp(systemlist.names[i], "Blix", 4) == NULL) {
- strcat(tmpstr, "/blixphoto.rgb");
- } else {
- strcat(tmpstr, "/noimage.rgb");
- }
- image = iopen(tmpstr, "r");
- }
- if (image != NULL) {
- draw_image(image,
- 0.18-(i&1)*0.16, 0.32-(i&1)*0.16, 0.683 - i*0.1, 0.823 - i*0.1);
- iclose(image);
- }
- }
- gflush();
- break;
- case WORLDHIGH:
- getsize(&sizex, &sizey);
- ortho2(0, sizex, 0, sizey);
- set_fontcolor(0x0000A0A0, 0x00E0E0);
- set_fontsize(0.060);
- draw_stringXY(0.04, 0.94, "The Best Players of the World:");
- sprintf(tmpstr,"after %d runs", (int) worldlist.game);
- set_fontsize(0.043);
- draw_stringXY(0.35, 0.87, tmpstr);
- for (i=0; i< 7; i++) {
- set_fontcolor((7.0-i)*0x202203, (7-i)*0x242400);
- if (worldlist.names[i] != NULL &&
- *(worldlist.names[i]) != '\0') {
- draw_stringXY(0.57, 0.74 - i * 0.1, worldlist.names[i]);
- }
- set_fontcolor(0x05122d, 0x08102D);
- if (worldlist.hosts[i] != NULL &&
- *(worldlist.hosts[i]) != '\0') {
- strcpy(tmpstr,"(");
- strcat(tmpstr, worldlist.hosts[i]);
- strcat(tmpstr,")");
- draw_stringXY(0.57, 0.69 - i * 0.1, tmpstr);
- }
- set_fontcolor((11.0-i)*0x111213, (11-i)*0x131313);
- draw_stringXY(0.50, 0.74 - i * 0.1, "pts");
- }
- set_fontsize(0.053);
- for (i=0; i<7; i++) {
- set_fontcolor((7-i)*0x202000, (7-i)*0x242400);
- sprintf(tmpstr, "%d", (int) worldlist.scores[i]);
- draw_stringXY(0.49 - (strlen(tmpstr)* 0.032), 0.74 - i * 0.1, tmpstr);
- }
- for (i=0; i<7; i++) {
- image = NULL;
- if (worldlist.images[i] != NULL && *(worldlist.images[i]) != '\0')
- image = iopen(worldlist.images[i], "r");
- if (image == NULL) {
- strcpy(tmpstr, datadir);
- if (strncmp(worldlist.names[i], "Blix", 4) == NULL) {
- strcat(tmpstr, "/blixphoto.rgb");
- } else {
- strcat(tmpstr, "/noimage.rgb");
- }
- image = iopen(tmpstr, "r");
- }
- if (image != NULL) {
- draw_image(image,
- 0.18-(i&1)*0.16, 0.32-(i&1)*0.16, 0.683 - i*0.1, 0.823 - i*0.1);
- iclose(image);
- }
- }
- gflush();
- break;
- }
- popmatrix();
- }
-
-
- void reset_rot(void) {
- rvec[0] = 0;
- rvec[1] =0;
- rvec[2] = 0;
- rvec[3] = 1;
- build_matrix();
- }
-
-
- void build_matrix(void) {
- build_rotmatrix(rotmat, rvec);
- minvert(rotmat, invrotmat);
- }
-
-
- void reset_transforms(void) {
- rvec[0] = rvec[1] = rvec[2] = 0.0;
- rvec[3] = 1.0;
- trans[0] = trans[1] = trans[2] = 0.0;
- trans[2] = TRANS;
- set_perspective();
- build_matrix();
- }
-
- void stop_spin(void) {
- spinrot[0] = 0;
- spinrot[1] = 0;
- spinrot[2] = 0;
- spinrot[3] = 1;
- }
-
- void toggle_zbuf(void) {
- zbuf = !zbuf;
- zbuffer(zbuf);
- draw_whatever();
- }
-
- void build_again(void) {
- free_arcs();
- init_maze();
- build_maze(0, Lod);
- draw_whatever();
- }
-
-
- void set_lod(int l) {
- Lod = l-1;
- free_arcs();
- if (Lod >= EXTRA_LIGHT )
- lmbind(LIGHT1,2);
- else
- lmbind(LIGHT1,0);
- if (Lod >= EXTRA_FINE) {
- sphmode(SPH_DEPTH, 12);
- } else {
- if (Lod >= WALLS_UP) {
- sphmode(SPH_DEPTH, 10);
- } else {
- sphmode(SPH_DEPTH, 8);
- }
- }
- shademodel(GOURAUD);
- build_maze(0, Lod);
- draw_whatever();
- }
-
- void toggle_report(void) {
- report_nodenum = !report_nodenum;
- }
-
-
- void set_perspective(void) {
-
- static float t = TRANS;
- float val;
-
- if (t == trans[2])
- return;
- val = trans[2]*SCALE*TANFOVY;
- /*ortho(val, -val,
- val, -val, NEAR,
- -trans[2] + EXTRA);*/
- y_pos = trans[1]/(-val);
- set_trackball(1.0/(-val), y_pos);
- t = trans[2];
- }
-
-
-
- /*_________________________________________________________________________
- |
- | init_windows - initalize gl window
- |
- */
-
- void init_windows(void) {
-
- foreground();
- if (getgdesc(GD_BITS_NORM_DBL_RED) == 0 ||
- getgdesc(GD_BITS_NORM_DBL_GREEN) == 0 ||
- getgdesc(GD_BITS_NORM_DBL_BLUE) == 0) {
- fprintf(stderr, "Blix requires RGB mode which is not "
- "supported on your machine\n");
- exit (1);
- }
- if (getgdesc(GD_BITS_NORM_ZBUFFER) == 0) {
- fprintf(stderr, "Blix requires a zbuffer which is not "
- "supported on your machine\n");
- exit(1);
- }
- if (getgdesc(GD_SCRNTYPE) == GD_SCRNTYPE_NOWM) {
- prefposition(0, getgdesc(GD_YPMAX)/3-1,
- 0, getgdesc(GD_YPMAX)/3-1);
- }
- minsize(300,300);
- winopen("blix");
- wintitle("blix (demo only)");
- icontitle("blix");
- keepaspect(1,1);
- minsize(100,100);
- winconstraints();
- RGBmode();
- displmode = DMRGBDOUBLE;
- doublebuffer();
- gconfig();
- chunksize(508);
- gflush();
- mmode(MVIEWING);
- zbuffer(TRUE);
- zmin = getgdesc(GD_ZMIN) & 0xffffff00;
- zmax = getgdesc(GD_ZMAX) & 0xffffff00;
- lsetdepth(zmin, zmax);
- cpack(0x00000000);
- czclear(0x00000000, zmax);
- subpixel(TRUE);
- can_do_textures = getgdesc(GD_TEXTURE);
- }
-
-